<?php

namespace app\actions;

use app\components\WebController;
use app\controllers\UserController;
use app\models\User;
use yii\base\Action;

class BaseUserAction extends Action {

    public $modelClass = NULL;
    /**
     * @var User
     */
    public $user;
    public $pageSize = 10;

    public $title = '';
    public $layout;

    /**
     * @var UserController
     */
    public $controller;

    public function beforeRun() {
        $this->user = \Yii::$app->user->identity;
        if ($this->layout) {
            $this->controller->layout = $this->layout;
        }
        return parent::beforeRun();
    }

    public function render($params = [], $view = NULL) {
        $this->controller->view->title = $this->title;
        if (!isset($params['user'])) {
            $params['user'] = $this->user;
        }
        return $this->controller->render($params, $view);
    }

    public function findModel($id, $modelClass = NULL) {
        if (NULL === $modelClass) {
            $modelClass = $this->modelClass;
        }
        return $this->controller->findModel($id, $modelClass);
    }

    public function getParam($name = NULL, $defaultValue = NULL){
        return $this->controller->getParam($name, $defaultValue);
    }
}